﻿using Rsd.Dudu;
using Rsd.Dudu.Core;
using Rsd.Dudu.Log;
using Rsd.Dudu.ModelProvider;
using Rsd.Faith.Core;
using Rsd.Faith.Models;
using Rsd.Faith.Sys.Core;
using System;
using System.Collections.Generic;
using System.Data;
using System.Web;

namespace Rsd.Faith.Sys.Services
{
    /// <summary>
    /// 
    /// </summary>
    public class UserService: BizService<SysUsersModel>, IUserService
    {
        
        /// <summary>
        /// 
        /// </summary>
        public override ServiceProxcy Proxcy
        {
            get
            {
                return ServiceProxcy.Session;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public UserService()
        { }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="usrname"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public bool ValidateUserNameAndPassword(string usrname,string password)
        {
           
            var user = MyType.GetType<SysUsersModel>().GetObject(obj => obj.DengLuMing == usrname);
            if (user == null)
            {
                return false;
            }

            return user.MiMa == password;
            
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="usrname"></param>
        /// <returns></returns>
        public SysUsersModel GetUserObject(string usrname)
        {
            return MyType.GetType<SysUsersModel>().GetObject(obj => obj.DengLuMing == usrname);
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="dengluming"></param>
        /// <param name="xingming"></param>
        /// <param name="mima"></param>
        /// <returns></returns>
        public SysUsersModel NewUser(string dengluming, string xingming, string mima)
        {
            var obj = new SysUsersModel() { DengLuMing = dengluming, XingMing = xingming,MiMa = mima };
            obj.SetState(Dudu.BizModel.ObjectStateType.New);
            base.Save(obj);
      
            return obj;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="pwd1"></param>
        /// <param name="pwd2"></param>
        /// <returns></returns>
        public bool SetPassword(string userid,string pwd1, string pwd2)
        {
           
            var user = MyType.GetType<SysUsersModel>().GetObject(obj => obj.Key == userid);
            return user != null;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="oldpwd"></param>
        /// <param name="newpwd1"></param>
        /// <param name="newpwd2"></param>
        /// <returns></returns>
        public bool UpdatePassword(string userid, string oldpwd, string newpwd1, string newpwd2)
        {
            var user = MyType.GetType<SysUsersModel>().GetObject(obj => obj.Key == userid);
            return user != null;
        }

        public override dynamic GetMonitorInfo()
        {
            throw new NotImplementedException();
        }
    }
}